that can have more than one of (waypoints, tracks, routes) in one file.
This doesn't get it for every format (or even for MPS output) but it
helps some of our cases...
void route_add_wpt(route_head *rte, waypoint *wpt);
void route_del_wpt(route_head *rte, waypoint *wpt);
void route_add_head(route_head *rte);
+void track_add_head(route_head *rte);
void route_disp_all(route_hdr, route_trl, waypt_cb);
void route_free (route_head *);
void route_flush( queue *);
*/
case 101:
track_head = route_head_alloc();
- route_add_head(track_head);
+ track_add_head(track_head);
track_head->rte_name = xstrndup(rec->wpt.CustTrkHdr.name, sizeof(rec->wpt.CustTrkHdr.name));
sz = be_read32(&rec->wpt.CustTrkHdr.number);
tp = (Custom_Trk_Point_Type *) ((char *) pdb_rec->data + sizeof(rec->wpt.CustTrkHdr));
break;
case tt_trk:
trk_head = route_head_alloc();
- route_add_head(trk_head);
+ track_add_head(trk_head);
in_trk++;
break;
case tt_trkpt:
fprintf(ofd, "</desc>\n");
}
}
- if (waypointp->altitude) {
+ if (waypointp->altitude != unknown_alt) {
fprintf(ofd, "<ele>\n%f\n</ele>\n",
waypointp->altitude);
}
static
void gpx_track_pr()
{
- route_disp_all(gpx_track_hdr, gpx_track_tlr, gpx_track_disp);
+ track_disp_all(gpx_track_hdr, gpx_track_tlr, gpx_track_disp);
}
static void
fprintf(ofd, "xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\n");
gpx_write_time( now, "time" );
- switch(global_opts.objective) {
- case trkdata:
- gpx_track_pr();
- break;
- case rtedata:
- gpx_route_pr();
- break;
- case wptdata:
- waypt_disp_all(gpx_waypt_pr);
- break;
- default:
- break;
- }
+
+ waypt_disp_all(gpx_waypt_pr);
+ gpx_track_pr();
+ gpx_route_pr();
fprintf(ofd, "</gpx>\n");
}
track_head = route_head_alloc();
track_head->rte_name = xstrdup(trkname);
- route_add_head(track_head);
+ track_add_head(track_head);
*trk = track_head;
while (trk_count--) {
char recType;
int reclen;
- int skipMe;
+ int morework;
mps_ver_in = 0; /* although initialised at declaration, what happens if there are two mapsource
input files? */
printf("static icon_mapping_t icon_table[] = {\n");
#endif
+ morework = 1;
+ while (morework && !feof(mps_file_in)) {
- while (!feof(mps_file_in)) {
-
- /* skip over this record, unless.... */
- skipMe = 1;
/* Read record length of next section */
fread(&reclen, 4, 1, mps_file_in);
reclen = le_read32(&reclen);
/* Read the record type "flag" in - using fread in case in the future need more than one char */
fread(&recType, 1, 1, mps_file_in);
-
- if (recType == 'W') {
+ switch (recType) {
+ case 'W':
/* Waypoint record */
/* With routes, we need the waypoint info that reveals, for example, the symbol type */
- if ((global_opts.objective == wptdata) || (global_opts.objective == rtedata)) {
- mps_waypoint_r(mps_file_in, mps_ver_in, &wpt);
+ mps_waypoint_r(mps_file_in, mps_ver_in, &wpt);
#ifdef DUMP_ICON_TABLE
- printf("\t{ %4u, \"%s\" },\n", icon, wpt->shortname);
+ printf("\t{ %4u, \"%s\" },\n", icon, wpt->shortname);
#endif
- skipMe = 0;
- }
- }
+ break;
- if (recType == 'R') {
+ case 'R':
/* Route record */
- if (global_opts.objective == rtedata) {
- mps_route_r(mps_file_in, mps_ver_in, &rte);
- skipMe = 0;
- }
- }
+ mps_route_r(mps_file_in, mps_ver_in, &rte);
+ break;
- if (recType == 'T') {
+ case 'T':
/* Track record */
- if (global_opts.objective == trkdata) {
- mps_track_r(mps_file_in, mps_ver_in, &trk);
- skipMe = 0;
- }
- }
+ mps_track_r(mps_file_in, mps_ver_in, &trk);
+ break;
- if (recType == 'V') {
+ case 'V':
/* Mapset record */
mps_mapsetname_r(mps_file_in, mps_ver_in);
- skipMe = 0;
/* Last record in the file */
+ morework = 0;
break;
- }
-
- if (skipMe == 1) {
+ default:
+ /* Unknown record type. Skip over it. */
fseek(mps_file_in, reclen, SEEK_CUR);
}
+
} /* while (!feof(mps_file_in)) */
#ifdef DUMP_ICON_TABLE
fread(&recType, 1, 1, mps_file_temp);
}
}
- route_disp_all(mps_trackhdr_w_wrapper, mps_noop, mps_trackdatapoint_w_wrapper);
+ track_disp_all(mps_trackhdr_w_wrapper, mps_noop, mps_trackdatapoint_w_wrapper);
}
if (mpsmergeout) {
track_head->rte_name = xstrdup(trkname);
}
trk_num++;
- route_add_head(track_head);
+ track_add_head(track_head);
}
thisWaypoint->creation_time = dateTime;
route_disp_all(psit_routehdr_w_wrapper, psit_noop, psit_waypoint_w_wrapper);
}
if (global_opts.objective == trkdata) {
- route_disp_all(psit_trackhdr_w_wrapper, psit_noop, psit_trackdatapoint_w_wrapper);
+ track_disp_all(psit_trackhdr_w_wrapper, psit_noop, psit_trackdatapoint_w_wrapper);
}
mkshort_del_handle(mkshort_handle);
#include "defs.h"
static queue my_route_head;
+static queue my_track_head;
static int rte_head_ct;
static int rte_waypts;
route_init(void)
{
QUEUE_INIT(&my_route_head);
+ QUEUE_INIT(&my_track_head);
}
unsigned int
rte_head_ct++;
}
+void
+track_add_head(route_head *rte)
+{
+ ENQUEUE_TAIL(&my_track_head, &rte->Q);
+ QUEUE_INIT(&rte->waypoint_list);
+}
+
void
route_add_wpt(route_head *rte, waypoint *wpt)
{
}
}
-void
-route_disp_all(route_hdr rh, route_trl rt, waypt_cb wc)
+void
+common_disp_all(queue *qh, route_hdr rh, route_trl rt, waypt_cb wc)
{
queue *elem, *tmp;
- QUEUE_FOR_EACH(&my_route_head, elem, tmp) {
+ QUEUE_FOR_EACH(qh, elem, tmp) {
const route_head *rhp;
rhp = (route_head *) elem;
if (rh) (*rh)(rhp);
if (rt) (*rt)(rhp);
}
}
+
+void
+route_disp_all(route_hdr rh, route_trl rt, waypt_cb wc)
+{
+ common_disp_all(&my_route_head, rh, rt, wc);
+}
+
+void
+track_disp_all(route_hdr rh, route_trl rt, waypt_cb wc)
+{
+ common_disp_all(&my_track_head, rh, rt, wc);
+}
+
void
route_flush(queue *head)
{
route_flush_all()
{
route_flush(&my_route_head);
+ route_flush(&my_track_head);
}
{
queue *elem, *tmp;
- queue *q;
QUEUE_FOR_EACH(head, elem, tmp) {
- q = dequeue(elem);
- waypt_free((waypoint *) q);
+ waypoint *q = (waypoint *) dequeue(elem);
+ waypt_free(q);
}
}